﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dracham.MapEditor.Maps;
using System.Xml;
using Dracham.MapEditor.Singleton;

namespace Dracham.MapEditor.Zones.Events.Actions
{
    public class Teleport : Action
    {
        private String zone;

        public Int32 X { get; set; }
        public Int32 Y { get; set; }
        public Zone Zone
        {
            get
            {
                return DrachamMapEditor.ZoneManager.GetZoneById(this.zone);
            }
            set
            {
                this.zone = value.Id;
            }
        }

        public Teleport() { }
        public Teleport(Int32 x, Int32 y, Zone zone)
        {
            this.X = x;
            this.Y = y;
            this.zone = zone.Id;
        }

        public static Action FromXmlNode(XmlNode node)
        {
            Teleport tp = new Teleport();

            tp.X = node.Attributes.GetInt32("X");
            tp.Y = node.Attributes.GetInt32("Y");
            tp.zone = node.Attributes["Zone"].Value;

            return tp;
        }

        public override XmlNode ToXmlNode()
        {
            XmlNode node = DrachamMapEditor.ZoneManager.CreateElement("Teleport");

            node.Attributes.Append(DrachamMapEditor.ZoneManager.CreateAttribute("X", this.X.ToString()));
            node.Attributes.Append(DrachamMapEditor.ZoneManager.CreateAttribute("Y", this.X.ToString()));
            node.Attributes.Append(DrachamMapEditor.ZoneManager.CreateAttribute("Zone", this.Zone.Id));

            return node;
        }
    }
}